﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.BLL;
using KeRui.Common;

public partial class Manage_Cms_FrameTree : System.Web.UI.Page
{
    protected List<KeRui.Model.CmsNode> listCmsNode;
    KeRui.BLL.CmsNode bllCmsNode = new CmsNode();
    string ym = "";//跳转的页面方向
    protected int siteID = PageRequest.GetInt("siteID", -1);
    protected int nodeType = PageRequest.GetInt("nodeType", -1);
    protected void Page_Load(object sender, EventArgs e)
    {
        listCmsNode = bllCmsNode.GetList(PageRequest.GetInt("siteid", -1));
    }

    #region 列表显示

    protected string showNodeList(int pNodeID, int siteID, int nodeType)
    {

        if (nodeType == -1)
        {
            return nodeList(pNodeID, siteID);
        }
        else
        {
            return nodeList(pNodeID, siteID, nodeType);
        }
    }
    protected string nodeList(int pNodeID, int siteID)
    {
        List<KeRui.Model.CmsNode> list = new List<KeRui.Model.CmsNode>();
        list = bllCmsNode.GetListByPId(pNodeID, siteID);
        ym = "ContentList.aspx";
        StringBuilder RetStr = new StringBuilder();
        foreach (KeRui.Model.CmsNode model in list)
        {
            RetStr.Append(
                 "<tr class=\"tdbg\" onmouseover=\"this.className='tdbg-dark';\" onmouseout=\"this.className='tdbg';\" >" +
                     "<td style=\"width:100%;\">" + state(model, pNodeID) + "</td>" +
                 "</tr>");
            if (model.ChildNum != 0)
            {
                RetStr.Append("<tr id=\"tbl" + model.NodeID + "\" style=\"display:" + (pNodeID == 0 ? "" : "none") + "\"><td colspan=\"7\">");
                RetStr.Append("<table style=\"width:100%;\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" >");
                RetStr.Append(nodeList(model.NodeID, siteID));
                RetStr.Append("</table>");
                RetStr.Append("</td></tr>");
            }
        }
        return RetStr.ToString();
    }
    protected string nodeList(int pNodeID, int siteID,int nodeType)
    {
        List<KeRui.Model.CmsNode> list = new List<KeRui.Model.CmsNode>();
        list = bllCmsNode.GetListBynodeType( siteID, nodeType);
        ym = "/Manage/Project/wjjxj/QandA.aspx";
        StringBuilder RetStr = new StringBuilder();
        foreach (KeRui.Model.CmsNode model in list)
        {
            RetStr.Append(
                 "<tr class=\"tdbg\" onmouseover=\"this.className='tdbg-dark';\" onmouseout=\"this.className='tdbg';\" >" +
                     "<td style=\"width:100%;\">" + state(model, pNodeID,nodeType) + "</td>" +
                 "</tr>");
        }
        return RetStr.ToString();
    }
    private string state(KeRui.Model.CmsNode model, int pNodeID)
    {
        StringBuilder RetStr = new StringBuilder();
         if (model.ChildNum != 0)
                {
                    RetStr.Append("<span style=\"width:" + (model.Depth * 30) + "px;\">&nbsp;</span>");
                }
                else
                {
                    RetStr.Append("<span style=\"width:" + (model.Depth * 30 + 16) + "px;\">&nbsp;</span>");
                }
                if (model.ChildNum != 0)
                {
                    RetStr.Append("<img align=\"absmiddle\" style=\"cursor: pointer\" onclick=\"displayChildren('tbl" + model.NodeID + "',this);\" src=\"/Manage/Pic/tree/" + (pNodeID == 0 ? "minus" : "plus") + ".gif\">");
                }
        RetStr.Append("<img align=\"absmiddle\" border=\"0\" src=\"/Manage/Pic/tree/folder.gif\" />");
        RetStr.AppendFormat("<a href=\"javascript:void(0);\" onclick=\"parent.document.getElementById('contentedit').src='"+ym+"?siteid={1}&nodeid={2}&datatype={3}'\">{0}</a><font style=\"color:blue\">({2})</font>", model.NodeName, KeRui.Common.PageRequest.GetInt("siteid", -1), model.NodeID, PageRequest.GetString("datatype"));
        return RetStr.ToString();
    }
    private string state(KeRui.Model.CmsNode model, int pNodeID, int nodeType)
    {
        StringBuilder RetStr = new StringBuilder();
        RetStr.Append("<span style=\"width:30px;\">&nbsp;</span>");
        RetStr.Append("<img align=\"absmiddle\" border=\"0\" src=\"/Manage/Pic/tree/folder.gif\" />");
        RetStr.AppendFormat("<a href=\"javascript:void(0);\" onclick=\"parent.document.getElementById('contentedit').src='" + ym + "?siteid={1}&nodeid={2}&datatype={3}'\">{0}</a><font style=\"color:blue\">({2})</font>", model.NodeName, KeRui.Common.PageRequest.GetInt("siteid", -1), model.NodeID, PageRequest.GetString("datatype"));
        return RetStr.ToString();
    }

    #endregion
}
